$(function(){
	var url = window.location.href;
    // baseUrl = "http://bc6d5cee.ngrok.io/";
    baseUrl = "https://api.tkzpz.com/";
	$(".nav").load("top-nav.html",function(){
		// 点击个人中心
	    $(".personal-icon").on("click",function(){
	        var token = $.cookie('token_access');
	        if(token == undefined){
	            window.location.href="login.html?url="+url;
	        }else{
	        	window.location.href="center.html"
	        }
	    })
	    // 判断是否是用户中心(yes:红，no:白)
	    if(url.indexOf("center") >= 0 || url.indexOf("login") >= 0 ){
	        $(".personal-icon").addClass("activeicon");
	        $("nav ul li").removeClass('active');
	    }else{
	        $(".personal-icon").removeClass("activeicon");
	    }
	    if(url.indexOf("film_list") >= 0){
	        $("nav ul li").removeClass('active');
	        $("nav ul .li-film").addClass('active');
	    }else if(url.indexOf("index") >= 0){
	    	$("nav ul li").removeClass('active');
	        $("nav ul .li-index").addClass('active');
	    }else{
	        $("nav ul li").removeClass('active');
	    }
	    // 轮播图
          $.ajax({
              url: window.baseUrl+'api/index/index',
              type: 'get',
              contentType: false,
              processData: false,
              success: function (data) {
                  $('.logo').html(data.datas.appName[0].caption)
                  $('title').html(data.datas.appName[0].caption)
              }
          });
	});
    // 点击搜索
    $(".search-box").load("search.html",function(){
    	$(".search").on("click",function(){
			var ishide = $(".search-box").hasClass('searchide');
			if(ishide){
				$(".search-box").removeClass('searchide');
			}else{
				$(".search-box").addClass('searchide');
			}
		})
		$(".search-input a").on("click",function(){
			// 视频筛选列表
	        var area = '';
	        var type = '';
	        var name = '';
	        var pageNum = 1;
	        var pageSize = 10;
	        var sort = '';
	        name = $(".search-input input").val();
	        if(name != ''){
	        	search(area,type,name,pageNum,pageSize,sort);
	        }
	        function search(area,type,name,pageNum,pageSize,sort){
	        	$.ajax({
	                url: window.baseUrl+'api/movie/list',
	                type: 'POST',
	                data: {
	                	area:area,
	                	type:type,
	                	name:name,
	                	pageNum:pageNum,
	                	pageSize:pageSize,
	                	sort:sort
	                },
	                success: function (data) {
	                    var searchListStr = '';
	                    $(".search-result span").html(data.datas.result.length);
	                    $(".search-result").show();
	                    for(var i = 0;i<data.datas.result.length;i++){
	                    	if(data.datas.result[i].tag == ''){
                                var setTag = ''
                            }else{
                                var setTag = '<div class="hot"><span>'+data.datas.result[i].tag+'</span></div>'
                            }
	                    	searchListStr = searchListStr + '<li><div class="piclist-img">';
	                    	searchListStr = searchListStr + '<a href="detail.html?id='+data.datas.result[i].id+'" >';
		              		searchListStr = searchListStr + '<img src="'+data.datas.result[i].logo+'" alt="">';
		              		searchListStr = searchListStr + '<div class="definition">'+data.datas.result[i].clarity+'</div>';
		                	searchListStr = searchListStr +setTag+ '</a></div>';
		                	searchListStr = searchListStr + '<div class="piclist-title">'+data.datas.result[i].movieName+'</div>';
		                	searchListStr = searchListStr + '</li>';
	                    }
	                    $(".list ul").html(searchListStr)
	                }
	            });
	        }
		})
    });

})